// FrogRenameAutoNumDialog.cpp : Implementation of CFrogRenameAutoNumDialog

#include "stdafx.h"
#include "FrogRenameAutoNumDialog.h"
#include "FrogMessageBox.h"
#include "..\FilerFrogUtils\FilerFrogUtils.h"

// CFrogRenameAutoNumDialog

CFrogRenameAutoNumDialog::CFrogRenameAutoNumDialog(HICON hIcon):
CFrogOrderFilesDialog(hIcon),
m_StartNumStr(L"1"),
m_StartNum(1)
{
}

LRESULT CFrogRenameAutoNumDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CFrogOrderFilesDialog::OnInitDialog(uMsg, wParam, lParam, bHandled);

	HWND spinHwnd = GetDlgItem(IDC_SPIN);
	::SendMessage(spinHwnd, (UINT) UDM_SETRANGE, (WPARAM)0, (LPARAM)MAKELONG((short)UD_MAXVAL, (short)0));

	return 0;
}

LRESULT CFrogRenameAutoNumDialog::OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	bHandled = TRUE;
	// TODO: Add your control notification handler code here
	DoDataExchange(TRUE);
	UpdateSortedFilesList();

	if(!FilerFrogUtils::FromString<int>(m_StartNum, wstring(m_StartNumStr), std::dec))
	{
		FrogMessageBox(m_hWnd, L"Please Enter a Valid Number", L"FilerFrog - Rename", 0);
		m_StartNumStr = L"1";
		m_StartNum = 1;
		return TRUE;
	}

	RunAsyncCommandWithProgressBar(false);
	EndDialog(wID);
	return 0;
}

void CFrogRenameAutoNumDialog::ExecuteCommand()
{
	m_FilesRefactor.RenameFilesAutoNumbering(m_LastResult, m_OutFilesList, m_StartNum);
}